// pages/recruit/discoverAnchor/discoverAnchor.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 基本参数
    resume_info: [],
    resume_id: '',

    // 开关
    flag_company: true,
    flag_normal: true,
    flag_notime: true,
    flag_allnotime: true,

  },
  //去付钱
  go_pay() {
    wx.navigateTo({
      url: '../../payment/index/index',
    })
  },
  //剩余发布次数
  residue_time() {
    wx.request({
      url: app.globalData.url + 'api/recruit/limit/number',
      data: {
        token: app.globalData.token,
      },
      method: 'POST',
      success: (e) => {
        // console.log(e)
        let last_time = e.data.data.is_send;
        this.setData({
          last_time: last_time,
        })
      },
    })
  },
  //去发布职位
  go_postJob() {
    this.residue_time();
    if (this.data.last_time <= 0) {
      wx.showModal({
        content: '职位发布数量已用完,暂不能发布新的职位',
        showCancel: false,
        confirmText: '好的',
        confirmColor: '#d0a76c',
      })
    } else {
      wx.navigateTo({
        url: '../postJob/postJob?discover=true&resume_id=' + this.data.resume_id,
      })
    }
    
  },
  //购买次数的判断
  contact_anchor() {
    let that = this;
    let is_perfect = that.data.is_perfect,
      residue_num = that.data.residue_num,
      is_issue = that.data.is_issue,
      is_linkup = that.data.is_linkup;
    if (is_perfect == 1) {
      if (is_linkup == 1) {
        //可以查看简历
        that.setData({
          flag_normal: false,
        })
      } else {
        if (residue_num > 0) {
          //可以查看简历
          that.setData({
            flag_normal: false,
          })
        } else {
          //不可查看简历
          if (is_issue == "0") {
            //未发布过职位
            that.setData({
              flag_notime: false,
            })
          } else {
            //已经发布过职位
            that.setData({
              flag_allnotime: false,
            })
          }
        }
      }

    } else {
      //显示 提醒完善公司信息
      that.setData({
        flag_company: false,
      })
    }

  },
  //完善公司信息
  perfect_company() {
    let that = this;
    that.setData({
      flag_company: true,
    })
    wx.navigateTo({
      url: '../function/function?flag=company_flag&discover=true',
    })
  },
  //打电话
  click_call() {
    let that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.resume_info.telephone,
      success(e) {
        console.log(e)
        if (that.data.is_linkup != 1) {
          wx.request({
            url: app.globalData.url + 'api/recruit/buy/residue/number',
            data: {
              token: app.globalData.token,
              resume_id: that.data.resume_id,
            },
            method: 'POST',
            success: function(e) {
              console.log(e)
              that.get_companyInfo();
            },
          })
        }

      }
    })
  },

  //得到简历简历数据
  get_resume(resume_id) {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/timing/resume/detail',
      data: {
        resume_id: resume_id,
      },
      method: 'POST',
      success: function(e) {
        console.log(e)
        let resume_info = e.data.data.resume;
        that.setData({
          resume_info: resume_info,
        })
      },
    })
  },
  //得到公司信息
  get_companyInfo() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/guild/company/add',
      data: {
        token: app.globalData.token,
        type: 2,
      },
      method: 'POST',
      success: function(e) {
        console.log(e);
        let is_perfect = e.data.data.company.is_perfect,
          residue_num = e.data.data.company.residue_num,
          is_issue = e.data.data.company.is_issue,
          is_linkup = e.data.data.company.is_linkup;
        //绑定赋值
        that.setData({
          is_perfect: is_perfect,
          residue_num: residue_num,
          is_issue: is_issue,
          is_linkup: is_linkup,
        })
      },
    })
  },
  // 关闭弹窗
  modal_hide() {
    let that = this;
    that.setData({
      flag_company: true,
      flag_normal: true,
      flag_notime: true,
      flag_allnotime: true,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    // console.log(options.id)
    let that = this;
    if (!options.id) {
      console.log("1不存在")      
    }else{
      that.setData({
        resume_id: options.id,
      })
    }
    if (!options.resume_id) {
      console.log("2不存在")
    } else {
      that.setData({
        resume_id: options.resume_id,
      })
    }

    that.get_resume(that.data.resume_id);
    that.get_companyInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this;
    that.get_resume(that.data.resume_id);
    that.get_companyInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})